<template>
  <div class="page-container">
    <!-- 导航栏包裹在 sticky 容器中 -->
    <div class="nav-wrapper">
      <nav class="nav-menu">
        <a href="#" class="nav-item">首页</a>
        <a href="#" class="nav-item">关于我们</a>
        <a href="#" class="nav-item">服务</a>
        <div class="nav-menu-right">
          <a href="#" class="nav-item nav-item-last">联系我们</a>
          <!-- 下拉菜单 -->
          <el-dropdown class="dropdown-menu" @command="handleColorChange">
            <span class="el-dropdown-link">
              修改背景<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item
                  v-for="option in colorOptions"
                  :key="option.value"
                  :command="option.value"
                >
                  {{ option.text }}
                </el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
      </nav>
    </div>

    <!-- 页面内容区域 -->
    <div class="content">
      <div class="content-wrapper">
        <div class="column left" :style="{ backgroundColor: background }">
          左侧内容
        </div>
        <div class="column middle" :style="{ backgroundColor: background }">
          中间内容
        </div>
        <div class="column right" :style="{ backgroundColor: background }">
          右侧内容
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "NavMenu",
  data() {
    return {
      background: "white",
      selectedColor: "",
      colorOptions: [
        { text: "白色", value: "white" },
        { text: "蓝色", value: "blue" },
        { text: "绿色", value: "green" },
      ],
    };
  },
  methods: {
    handleColorChange(value) {
      this.background = value;
    },
  },
};
</script>

<style scoped>
.page-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.nav-wrapper {
  position: sticky;
  top: 0;
  z-index: 1000;
  background-color: white;
}

.nav-menu {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background-color: #ffffff;
  border-bottom: 1px solid #ddd;
  max-width: 1000px;
  margin: 0 auto;
}

.nav-item {
  text-decoration: none;
  color: #333;
  font-size: 16px;
  padding: 8px 16px;
  transition: all 0.3s ease;
  position: relative;
}

.nav-item:hover {
  color: #007bff;
  transform: scale(1.05);
}

.nav-menu-right {
  margin-left: auto;
  display: flex;
  flex-flow: row nowrap;
  align-items: center;
}

.content {
  padding: 0;
  width: 100%;
  margin-top: 24px;
  flex: 1;
  display: flex;
  flex-flow: column nowrap;
}

.content-wrapper {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  width: 100%;
  height: 100%;
  max-width: 1032px;
  padding: 16px;
  margin: 0 auto;
}

.column {
  box-sizing: border-box;
  padding: 20px;
  background-color: #f0f0f0;
  border: 1px solid #ccc;
  text-align: center;
  overflow-y: auto;
}

/* 桌面端：三列 */
@media (min-width: 992px) {
  .column.left {
    width: 240px;
  }

  .column.middle {
    flex: 1;
  }

  .column.right {
    width: 300px;
  }
}

/* 平板端：两列 */
@media (min-width: 768px) and (max-width: 991px) {
  .column.left {
    width: 200px;
  }

  .column.middle {
    flex: 1;
  }

  .column.right {
    flex: 0 0 100%;
  }
}

/* 手机端：单列 */
@media (max-width: 767px) {
  .column {
    flex: 0 0 100%;
  }
}

.dropdown-menu {
  margin-left: auto; /* 靠右对齐 */
  padding-left: 16px;
}

.el-dropdown-link {
  font-size: 16px;
  color: #333;
  cursor: pointer;
  text-decoration: none;
}

.el-dropdown-link:hover {
  color: #007bff;
}
</style>
